﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;
using System.Collections.ObjectModel;

namespace Portal.Cms.Model
{
    public class GroupDataCategoryCls
    {
        public string GroupDataCategoryId;
        public string frkGroupDataId;
        public string Name;
        public string frkGroupDataCategoryId;
        public string frkDataLanguageId;
        public Collection<GroupDataCategoryCls> SubGroupDataCategories = new Collection<GroupDataCategoryCls> { };
        public int TotalTasks = 0;
        public string MapId;
    }

    public class GroupDataCategoryParser
    {
        public static GroupDataCategoryCls CreateInstance()
        {
            //tao 1 class trang....
            GroupDataCategoryCls oGroupDataCategoryCls = new GroupDataCategoryCls();
            return oGroupDataCategoryCls;
        }

        public static GroupDataCategoryCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            GroupDataCategoryCls oGroupDataCategoryCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oGroupDataCategoryCls;
        }


        public static GroupDataCategoryCls ParseFromDataRow(DataRow dr)
        {
            GroupDataCategoryCls oGroupDataCategoryCls = new GroupDataCategoryCls();
            oGroupDataCategoryCls.GroupDataCategoryId = XmlUtility.GetString(dr, "GroupDataCategoryId", true);
            oGroupDataCategoryCls.frkGroupDataId = XmlUtility.GetString(dr, "frkGroupDataId", true);
            oGroupDataCategoryCls.Name = XmlUtility.GetString(dr, "Name", true);
            oGroupDataCategoryCls.frkGroupDataCategoryId = XmlUtility.GetString(dr, "frkGroupDataCategoryId", true);
            oGroupDataCategoryCls.frkDataLanguageId = XmlUtility.GetString(dr, "frkDataLanguageId", true);
            oGroupDataCategoryCls.TotalTasks = XmlUtility.GetInt(dr, "TotalTasks", true);
            oGroupDataCategoryCls.MapId = XmlUtility.GetString(dr, "MapId", true);
            return oGroupDataCategoryCls;
        }

        public static GroupDataCategoryCls[] ParseFromDataTable(DataTable dtTable)
        {
            GroupDataCategoryCls[] GroupDataCategorys = new GroupDataCategoryCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                GroupDataCategorys[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return GroupDataCategorys;
        }




        public static GroupDataCategoryCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new GroupDataCategoryCls[0];
            }
            GroupDataCategoryCls[] GroupDataCategorys = new GroupDataCategoryCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                GroupDataCategorys[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return GroupDataCategorys;
        }
    }
}

